<template>
  <div class="dashboard-container">
    <el-row :gutter="20">
      <!-- 左侧日历和表格 -->
      <el-col :span="6">
        <el-card class="calendar-card">
          <div class="calendar-wrapper">
            <el-calendar v-model="currentDate">
              <template slot="dateCell" slot-scope="{ date, data }">
                <div :class="['custom-cell', data.isSelected ? 'current-day' : '']">
                  {{ date.getDate() }}
                </div>
              </template>
            </el-calendar>
          </div>
          <el-table :data="dailyData" class="time-table">
            <el-table-column
              prop="date"
              label="日期"
              width="80"
            ></el-table-column>
            <el-table-column prop="morning" label="上午"></el-table-column>
            <el-table-column prop="afternoon" label="下午"></el-table-column>
          </el-table>
        </el-card>
      </el-col>
      <div class="system-title-container">
        <h4 class="system-title">捷越人事管理系统</h4>
      </div>
      <!-- 右侧图表区 -->
      <el-col :span="18">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-card class="chart-card">
              <div class="chart-title">月度工时对比分析</div>
              <div ref="barChart" style="height: 300px"></div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="chart-card">
              <div class="chart-title">2025年数据产能趋势</div>
              <div ref="lineChart" style="height: 300px"></div>
            </el-card>
          </el-col>
        </el-row>

        <el-row :gutter="20" style="margin-top: 20px">
          <el-col :span="12">
            <el-card class="chart-card">
              <div class="chart-title">部门能力评估</div>
              <div ref="radarChart" style="height: 280px"></div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="chart-card">
              <div class="chart-title">数据产生效力</div>
              <div ref="pieChart" style="height: 280px"></div>
            </el-card>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  data() {
    return {
      currentDate: new Date(),
      dailyData: [
        { date: "02-01", morning: "正常", afternoon: "正常" },
        { date: "02-02", morning: "异常", afternoon: "正常" },
      ],
    };
  },
  mounted() {
    this.initCharts();
  },
  methods: {
    initCharts() {
      // 折线图增加更多配置
      const lineOption = {
        tooltip: { trigger: "axis" },
        xAxis: {
          type: "category",
          data: ["1月", "2月", "3月", "4月", "5月", "6月"],
          axisLabel: { rotate: 45 },
        },
        yAxis: {
          type: "value",
          axisLine: { show: true },
          splitLine: { show: false },
        },
        series: [
          {
            data: [65, 78, 83, 108, 95, 122],
            type: "line",
            smooth: true,
            areaStyle: { color: "rgba(64,158,255,0.2)" },
            lineStyle: { width: 3 },
            itemStyle: { color: "#409EFF" },
          },
        ],
      };

      // 新增柱状图配置
      const barOption = {
        tooltip: { trigger: "axis" },
        xAxis: {
          type: "category",
          data: ["研发部", "市场部", "测试部", "财务部"],
          axisLabel: { interval: 0 },
        },
        yAxis: { type: "value" },
        series: [
          {
            data: [120, 200, 150, 80],
            type: "bar",
            barWidth: "40%",
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#83bff6" },
                { offset: 1, color: "#188df0" },
              ]),
            },
          },
        ],
      };

      // 增强饼图配置
      const pieOption = {
        tooltip: { trigger: "item" },
        legend: { orient: "vertical", left: "right" },
        series: [
          {
            type: "pie",
            radius: ["40%", "70%"],
            roseType: "radius",
            data: [
              { value: 1048, name: "研发部" },
              { value: 735, name: "市场部" },
              { value: 580, name: "测试部" },
              { value: 335, name: "财务部" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };

      // 新增雷达图配置
      const radarOption = {
        tooltip: { trigger: "item" },
        radar: {
          indicator: [
            { name: "研发部", max: 100 },
            { name: "市场部", max: 100 },
            { name: "测试部", max: 100 },
            { name: "财务部", max: 100 },
            { name: "运维部", max: 100 },
          ],
        },
        series: [
          {
            type: "radar",
            data: [
              {
                value: [85, 75, 90, 65, 95],
                name: "当前指标",
                areaStyle: { color: "rgba(255, 153, 0, 0.2)" },
              },
            ],
          },
        ],
      };

      // 初始化所有图表
      echarts.init(this.$refs.lineChart).setOption(lineOption);
      echarts.init(this.$refs.barChart).setOption(barOption);
      echarts.init(this.$refs.pieChart).setOption(pieOption);
      echarts.init(this.$refs.radarChart).setOption(radarOption);
    },
  },
};
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
  background-color: #f5f7fa;
}

.calendar-card {
  margin-bottom: 20px;
}

.chart-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 15px;
}

.control-bar {
  margin-bottom: 20px;
  padding: 10px;
  background: #fff;
  border-radius: 4px;
}

.time-table {
  margin-top: 15px;
}

.current-day {
  background-color: #409eff;
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  line-height: 24px;
}
.chart-card {
  margin-bottom: 20px;
  transition: box-shadow 0.3s;
}

.chart-card:hover {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.chart-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  padding-left: 10px;
  border-left: 4px solid #409eff;
  margin-bottom: 20px;
}

.system-title-container {
  display: flex;
  justify-content: center;
  margin: 0px 0 30px;
  animation: fadeInDown 0.8s;
  height: 50px;
}

.system-title {
  font-size: 25px;
  font-weight: 600;
  color: #2c3e50;
  position: relative;
  padding-bottom: 30px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.system-title::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: #409eff;
  border-radius: 50px;
}

/* 添加入场动画 */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 移动端适配 */
@media (max-width: 768px) {
  .system-title {
    font-size: 22px;
    padding: 0 15px;
  }
}
</style>